package com.wskeee.ec.components
{
	import com.wskeee.ec.core.SkinableComponent;
	
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class Label extends SkinableComponent
	{
		protected var _autoSize:Boolean = true;
		protected var _text:String = "label";
		protected var _tf:TextField;
		
		public function Label(text:String = "label")
		{
			super();
			_text = text;
		}
		
		//========================= override ====================
		//---------------------
		//SkinableEomponent
		//---------------------
		override protected function initChildren():void
		{
			super.initChildren();
			initTxt();
		}
		
		protected function initTxt():void
		{
			_tf = new TextField();
			_tf.autoSize = TextFieldAutoSize.LEFT;
			addChild(_tf);
		}
		//========================= end =========================
		
		//========================= updateDisplayList ===========
		override protected function updateDisplayList():void
		{
			super.updateDisplayList();
			_tf.autoSize = TextFieldAutoSize.LEFT;
			_tf.height = height;
			_tf.embedFonts = getStyle("embedFonts") as Boolean;
			_tf.selectable = false;
			_tf.mouseEnabled = false;
			_tf.defaultTextFormat = new TextFormat(getStyle("fontFamily") as String, 
													getStyle("fontSize"), 
													getStyle("fontColor"));
			_tf.text = _text;	
			if(autoSize)
			{
				width = _tf.width;
				dispatchEvent(new Event(Event.RESIZE));
			}else
			{
				_tf.autoSize = TextFieldAutoSize.NONE;
				_tf.width = width;
			}
			height = _tf.height = 18;
		}
		//========================= end =========================

		//========================= get & set ===================
		public function get autoSize():Boolean
		{
			return _autoSize;
		}
		
		public function set autoSize(value:Boolean):void
		{
			_autoSize = value;
			invalidateDisplayList();
		}
		
		public function get tf():TextField
		{
			return _tf;
		}
		
		public function get text():String
		{
			return _text;
		}
		
		public function set text(value:String):void
		{
			_text = value;
			invalidateDisplayList();
		}
		
		public function set fontColor(value:Object):void
		{
			setStyle("fontColor",value);
			invalidateDisplayList();
		}
		//========================= end =========================
	}
}